import { PasswordValidators } from './password.validators';
import { FormControl, FormBuilder, Validators, FormGroup } from '@angular/forms';
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'change-password',
  templateUrl: './change-password.component.html',
  styleUrls: ['./change-password.component.css']
})
export class ChangePasswordComponent{
  form: FormGroup;
  constructor(fb: FormBuilder) { 
    this.form = fb.group({
      oldPassword: ['', 
        Validators.required, 
        PasswordValidators.oldpasswordValid],
      
      newPassword: ['', 
          [Validators.required,
          Validators.minLength(6)]
        ],
      
      rePassword: ['',
        [Validators.required]],
      },
      {
        validator: PasswordValidators.rePasswordValid
      }
  );
  }
  get oldPassword() {
    return this.form.get('oldPassword');
  }
  get newPassword() {
    return this.form.get('newPassword');
  }
  get rePassword() {
    return this.form.get('rePassword');
  }
}
